13 Java Tutorial > 13.1 Using the AT Command API > 13.1.1 Class ATCommand

13.1.1
The ATCommand class supports the execution of AT commands in much the same way as they would be executed over a serial interface. It provides a simple way to send strings directly to the device’s AT parsers.
13.1.1.1
There can be only exactly as many ATCommand instances as there are parsers on the device. If there are no more parsers available, the ATCommand constructor will throw ATCommand­FailedException. All AT parser instances support CSD. However from a Java application point of view it may make sense to have one dedicated instance for CSD call handling. Therefore, and also for historical reasons, only one parser with CSD support may be requested through the constructor. If more then one parser with CSD support is requested, the constructor will throw ATCommandFailedException.
ATCommand atc = new ATCommand(false);
/* An instance of ATCommand is created. CSD is not explicitly
* requested. */
} catch (ATCommandFailedException e) {
System.out.println(e);
The csdSupported() method returns the CSD capability of the connected instance of the device's AT parser. The method checks as well, if the current mode of the module supports CSD. Please notice that this check has not been done when opening the ATCommand instance.
release() releases the resources held by the instance of the ATCommand class. After calling this function the class instance cannot be used any more but the resources are free to be used by a new instance
13.1.1.2
An AT command is sent to the device by using the send() method. The AT command is sent as a string which must include the finalizing line feed "\r" or the corresponding line end charac­ter.
This send function is a blocking call, which means that the calling thread will be interrupted until the module returns a response. The function returns the response, the result code of the AT command, as a string.
Occasionally it may be infeasible to wait for an AT command that requires some time to be pro­cessed, such as AT+COPS. There is a second, non-blocking, send function which takes a sec­ond parameter in addition to the AT command. This second parameter is a callback instance, ATCommandResponseListener. Any response to the AT command is delivered to the callback instance when it becomes available. The method itself returns immediately. The ATComman­dResponseListener and the non-blocking send method are described in Section 13.1.2.
Note: Using the send methods with strings with incorrect AT command syntax will cause errors.
13.1.1.3
If a data connection is created with the ATCommand class, for instance with ‘atd’, an input stream is opened to receive the data from the connection. Similarly, an output stream can be opened to send data on the connection.
}     /* The example continues after the next block of text */
These streams behave slightly differently than regular data streams. The streams are not closed by using the close() method. A stream remains open until the release() method is called. A module can be switched from the data mode to the AT command mode by calling the break­Connection() method.
An IOException is thrown if any function of the I/O streams are called when the module is in AT command mode, except for read functions. The read function case is explained in more detail in Section 13.1.3. The ATCommand class does not report the result codes returned after data connection release.
Data Connections are not only used for data transfer over the air but also to access external hardware. Here is a list of at commands which open a data connection:
•
•
•
For data connection signaling see also Section 13.1.3.
13.1.1.4
For performance reasons no synchronization is done in the ATCommand class. If an instance of this class has to be accessed from different threads ensure that the send() functions, the release() function, the cancelCommand() function and the breakConnection() function are syn­chronized in the user implementation.